﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class CellAlarm_CellAnalyz : UserPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Mtitle.InnerText = ConfigurationManager.AppSettings["SystemName"].Substring(0, 6);
            MFoot.InnerText = DateTime.Now.Year.ToString() + "©"
                + ConfigurationManager.AppSettings["CompanyName"] + "Gt";
            string cell = Request.QueryString["cell_chname"].ToString();
            Msg.Text = cell;
            CellAnalyzBind(cell);            
        }
    }

    private void CellAnalyzBind(string argCell)
    {
        string sqlStr = @"SELECT * FROM(SELECT COUNTY,T1.CELL_CHNAME,'2G' AS NetType,T1.START_TIME,T1.RECOVER_TIME
                                   ,T3.MAIN_REASON,T3.SECOND_REASON
                              FROM AB_CELL_UNLINK T1  
                              LEFT JOIN (select CELL_CHNAME,START_TIME,MAIN_REASON,SECOND_REASON
                              from U_UNLINK_REASON_T) T3
                                ON T1.CELL_CHNAME = T3.CELL_CHNAME
                               AND T1.START_TIME = T3.START_TIME
                             WHERE T1.START_TIME > to_char(add_months(last_day(sysdate)+1,-1),'yyyy-MM-dd') 
                             UNION ALL
                            SELECT SUBSTR(T2.CELL_CHNAME,0,2) AS COUNTY,T2.CELL_CHNAME,'3G' AS NetType,T2.STARTED
                                   ,T2.CANCELED,T4.MAIN_REASON,T4.SECOND_REASON
                              FROM ALARM_TABLE_3G T2  
                              LEFT JOIN (select CELL_CHNAME,START_TIME,MAIN_REASON,SECOND_REASON
                              from U_UNLINK_REASON_T) T4
                                ON T2.CELL_CHNAME = T4.CELL_CHNAME
                               AND T2.STARTED = T4.START_TIME
                             WHERE C_NUMBER = '7786'
                               AND T2.CELL_CHNAME IS NOT NULL
                               AND T2.STARTED>to_char(add_months(last_day(sysdate)+1,-1),'yyyy-MM-dd')
                               AND (T2.CANCELED IS NULL OR TO_NUMBER((T2.CANCELED
                                  - T2.STARTED)*24*60) >= 1)
                               AND (TO_NUMBER(TO_CHAR(T2.STARTED,'HH24'))>5
                                   OR (NVL(TO_NUMBER(TO_CHAR(T2.CANCELED,'HH24')),0)>5
                                   OR T2.CANCELED IS NULL)))
                            WHERE Cell_Chname = '"+argCell+"' ORDER BY START_TIME";
        CellAnalyzList.DataSource = OracleHelper.ExecuteDataSet(sqlStr, CommandType.Text, null);
        CellAnalyzList.DataBind();
    }
}
